import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * 没有权限要求的基本页面
 *所有角色都可以访问
 */
//所有权限通用路由表 
//如首页和登录页和一些不用权限的公用页面
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},
{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: 'Dashboard',
    component: () => import('@/views/dashboard/index'),
    meta: {
      title: '首页',
      icon: 'dashboard',
    }
  }
  ]
}
// ,
// {
//   path: '/404',
//   component: () => import('@/views/404'),
//   hidden: true
// },
]
//异步挂载的路由
//动态需要根据权限加载的路由表
export const asyncRoutes = [
  // 个人信息2
  {
    path: '/personal',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Personal',
        component: () => import('@/pages/personal/index'),
        meta: { title: '个人信息', icon: 'personal', roles: ['管理员', '导师', '学生'] }
      }
    ]
  },
  // 详情页面
  {
    path: '/detail',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Personal',
        component: () => import('@/pages/manage/detail'),
      }
    ]
  },

  // 站点管理
  {
    path: '/manage',
    component: Layout,
    redirect: '/manage/swipe',
    name: 'Manage',
    meta: { title: '站点管理', icon: 'manage', roles: ['管理员'] },
    children: [
      {
        path: 'swipe',
        name: 'swipe',
        component: () => import('@/pages/manage/swipe.vue'),
        meta: { title: '轮播', icon: 'swipe' }
      },
      {
        path: 'notice',
        name: 'Notice',
        component: () => import('@/pages/manage/notice.vue'),
        meta: { title: '公告', icon: 'notice' }
      }, {
        path: 'classify',
        name: 'Classify',
        component: () => import('@/pages/manage/classify.vue'),
        meta: { title: '分类', icon: 'classify' }
      }, {
        path: 'publish',
        name: 'Publish',
        component: () => import('@/pages/manage/publish.vue'),
        // meta: { title: '分类', icon: 'tree' }
      }
    ]
  },

  // 我的评价
  {
    path: '/mycomment',
    component: Layout,
    children: [
      {
        path: 'mycomment',
        name: 'MyComment',
        // hidden: roleName === '管理员',
        component: () => import('@/pages/mycomment/mycomment'),
        meta: { title: '我的评价', icon: 'form', roles: ['学生'] }
      }
    ]
  },
    // 公告栏
    {
      path: '/noticeView',
      component: Layout,
      children: [
        {
          path: 'noticeView',
          name: 'noticeView',
          // hidden: roleName === '管理员',
          component: () => import('@/pages/notice/noticeView.vue'),
        },

      ]
    },

  // 教学管理
  {
    path: '/coursemanage',
    component: Layout,
    redirect: '/coursemanage/CourseQuery',
    name: 'CourseManage',
    meta: { title: '教学管理', icon: 'teach-manage' },
    children: [
      {
        path: 'CourseQuery',
        name: 'CourseQuery',
        component: () => import('@/pages/coursemanage/CourseQuery.vue'),
        meta: { title: '课程发布', icon: 'publish' , roles: ['管理员','导师']}
      },
      {
        path: 'TeacherQuery',
        name: 'TeacherQuery.vue',
        component: () => import('@/pages/coursemanage/TeacherQuery.vue'),
        meta: { title: '评价发布', icon: 'publish-review' ,roles: ['管理员','导师','学生']}
      },
      {
        path: 'toReview',
        name: 'toReview.vue',
        component: () => import('@/pages/coursemanage/toReview.vue'),
      },
      {
        path: 'toPublish',
        name: 'toPublish.vue',
        component: () => import('@/pages/coursemanage/toPublish.vue'),
      }
    ]
  },

  // 评价管理
  {
    path: '/evaluationmanage',
    component: Layout,
    redirect: '/evaluationmanage/CourseEvaluation',
    name: 'EvaluationManage',
    meta: { title: '评价管理', icon: 'review-manage' },
    children: [
      {
        path: 'CourseEvaluation',
        name: 'CourseEvaluation',
        component: () => import('@/pages/evaluationmanage/CourseEvaluation.vue'),
        meta: { title: '评价审核', icon: 'check', roles: ['管理员','导师'] }
      },
      {
        path: 'TeacherEvaluation',
        name: 'TeacherEvaluation',
        component: () => import('@/pages/evaluationmanage/TeacherEvaluation.vue'),
        meta: { title: '统计与查看', icon: 'see' ,roles: ['管理员','导师','学生'] }
      },
      {
        path: 'EvaView',
        name: 'EvaView',
        component: () => import('@/pages/evaluationmanage/EvaView.vue'),
      },
      {
        path: 'myReview',
        name: 'myReview',
        component: () => import('@/pages/evaluationmanage/myReview.vue'),
      }, {
        path: 'chart',
        name: 'chart',
        component: () => import('@/pages/evaluationmanage/chart.vue'),
      },
    ]
  },

    // 用户管理
    {
      path: '/userManage',
      component: Layout,
      children: [
        {
          path: 'index',
          name: 'userManage',
          component: () => import('@/pages/userManage/index'),
          meta: { title: '用户管理', icon: 'user-manage', roles: ['管理员'] }
        }
      ]
    },
    


  // 如果需要配置重定向404页面的话，需要配置在asyncRoutes的最后
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]
// 实例化vue的时候只挂载constantRouter
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
